/*************************************************************************
	> File Name: time_operation.c
	> Author: ma6174
	> Mail: ma6174@163.com 
	> Created Time: 2016年07月13日 星期三 14时50分53秒
 ************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>

void time_print(struct tm *p)
{
	char *Week[7] = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
	printf("%d年%.2d月%.2d日 %s %.2d:%.2d:%.2d\n", 
			(p->tm_year)+1900, p->tm_mon, p->tm_mday, Week[p->tm_wday], p->tm_hour, p->tm_min, p->tm_sec);
}
int main(void)
{
	struct timeval today;
	time_t now;
	struct tm *p_utc;
	struct tm *p_local;
	now = time(NULL);
	p_utc = gmtime(&now);
	printf("utc	: %d:%d:%d\n", p_utc->tm_hour, p_utc->tm_min, p_utc->tm_sec);
	printf("%s", asctime(p_utc));
	p_local = localtime(&now);
	printf("local	: %d:%d:%d\n", p_local->tm_hour, p_local->tm_min, p_local->tm_sec);
	printf("%s", asctime(p_local));
	printf("%s", ctime(&now));

	gettimeofday(&today, NULL);
	usleep(2000000);
	printf("%ld\n", today.tv_sec);

	time_t t1 = mktime(p_utc);
	sleep(2);
	printf("%ld %ld\n", t1, now);
	time_print(p_local);
}

